import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:study_online/entity/CourseRou.dart';
import 'package:study_online/entity/Subject.dart';
import 'package:study_online/global/colors.dart';
import 'package:study_online/global/r.dart';
import 'package:study_online/pages/homePage/views/GirdViewItem.dart';
import 'package:study_online/utils/jh_login_textfield.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        //appBar: AppBar(
        //  backgroundColor: Colors.black26,
        //  title: Text('container'),
        //),
        body: ComputerScienceView(),
      ),
    );
  }
}

class ComputerScienceView extends StatefulWidget {
  ComputerScienceView({Key key}) : super(key: key);

  @override
  _ComputerScienceViewState createState() {
    return _ComputerScienceViewState();
  }
}

class _ComputerScienceViewState extends State<ComputerScienceView> {
  int _selectIndex = 0;
  List<String> _categoryList = [
    '大一上学期',
    '大一下学期',
    '大二上学期',
    '大二下学期',
    '大三上学期',
    '大三下学期',
    '大四上学期',
    '大四下学期',
  ];
  List<Subject> _categoryList1 = [
    new Subject('计算机科学与技术导论', R.Jisuanjidaolun),
    new Subject('C语言程序设计', R.Cyuyan),
    new Subject('电路分析', R.Dianlufenxi),
    new Subject('物理学', R.Wuli),
    new Subject('高等数学上', R.Gaoshu),
    new Subject('大学英语1', R.Yingyu),
    new Subject('体育', R.Tiyu),
    new Subject('形势与政策', R.Xingshiyuzhengce),
    new Subject('军事理论', R.Junshi),
    new Subject('心理健康教育', R.Jiankang),
  ];
  List<Subject> _categoryList2 = [
    new Subject('模拟电子技术', R.Dianlufenxi),
    new Subject('线性代数', R.Xianxing),
    new Subject('离散数学', R.Lisan),
    new Subject('高等数学下', R.Gaoshu),
    new Subject('数据结构', R.Shuju),
    new Subject('大学英语2', R.Yingyu),
    new Subject('中国近代史纲要', R.Lishi),
    new Subject('形势与政策', R.Xingshiyuzhengce),
    new Subject('体育', R.Tiyu),
    new Subject('创业基础', 'assets/img/chuangye.png'),
    new Subject('心理健康教育', R.Jiankang),
  ];
  List<Subject> _categoryList3 = [
    new Subject('面向对象技术', R.Java),
    new Subject('数据库原理', R.Shujuku),
    new Subject('概率论与数理统计', R.Gailv),
    new Subject('数字电子技术', R.Shuzidianlu),
    new Subject('数值计算', R.Shuzhi),
    new Subject('医学信息学', R.Yixue),
    new Subject('大学英语3', R.Yingyu),
    new Subject('马克思主义原理与概论', R.Mks),
    new Subject('形势与政策', R.Xingshiyuzhengce),
    new Subject('体育', R.Tiyu),
  ];
  List<Subject> _categoryList4 = [
    new Subject('web技术', R.Web),
    new Subject('大型数据库技术', R.Daxing),
    new Subject('算法分析与设计', R.Suanfafenxi),
    new Subject('计算机组成原理与汇编语言', R.Jizu),
    new Subject('微机原理与接口技术', R.Weiji),
    new Subject('移动应用开发', R.Yidong),
    new Subject('应用英语', R.Yingyu),
    new Subject('体育', R.Tiyu),
    new Subject('毛泽东思量和中国特色社会主义理论体系概论', R.Maozhe),
    new Subject('形势与政策', R.Xingshiyuzhengce),
  ];
  List<Subject> _categoryList5 = [
    new Subject('软件工程', R.Ruanjian),
    new Subject('Java EE 应用开发', R.Javaee),
    new Subject('操作系统原理', R.Windows),
    new Subject('软件设计模式', R.Sheji),
    new Subject('计算机网络原理', R.Jiwang),
    new Subject('人工智能原理', R.Rengon),
    new Subject('计算机图形学', R.Opengl),
    new Subject('嵌入式系统原理与应用技术', R.Qianru),
    new Subject('Unix/Linux操作系统', R.Linuix),
  ];
  List<Subject> _categoryList6 = [
    new Subject('java程序设计', '_'),
    new Subject('模拟电子技术', '_'),
    new Subject('线性代数', '_'),
    new Subject('离散数学', '_'),
    new Subject('高等数学下', '_'),
    new Subject('数据结构', '_'),
    new Subject('大学英语2', '_'),
    new Subject('中国近代史纲要', '_'),
    new Subject('形势与政策', '_'),
    new Subject('创业基础', '_'),
    new Subject('心理健康教育', '_'),
  ];
  List<Subject> _categoryList7 = [
    new Subject('java程序设计', '_'),
    new Subject('模拟电子技术', '_'),
    new Subject('线性代数', '_'),
    new Subject('离散数学', '_'),
    new Subject('高等数学下', '_'),
    new Subject('数据结构', '_'),
    new Subject('大学英语2', '_'),
    new Subject('中国近代史纲要', '_'),
    new Subject('形势与政策', '_'),
    new Subject('创业基础', '_'),
    new Subject('心理健康教育', '_'),
  ];
  List<Subject> _categoryList8 = [
    new Subject('java程序设计', '_'),
    new Subject('模拟电子技术', '_'),
    new Subject('线性代数', '_'),
    new Subject('离散数学', '_'),
    new Subject('高等数学下', '_'),
    new Subject('数据结构', '_'),
    new Subject('大学英语2', '_'),
    new Subject('中国近代史纲要', '_'),
    new Subject('形势与政策', '_'),
    new Subject('创业基础', '_'),
    new Subject('心理健康教育', '_'),
  ];
  List<Subject> _girdViewList = [
    new Subject('计算机科学与技术导论', R.Jisuanjidaolun),
    new Subject('C语言程序设计', R.Cyuyan),
    new Subject('电路分析', R.Dianlufenxi),
    new Subject('物理学', R.Wuli),
    new Subject('高等数学上', R.Gaoshu),
    new Subject('大学英语1', R.Yingyu),
    new Subject('体育', R.Tiyu),
    new Subject('形势与政策', R.Xingshiyuzhengce),
    new Subject('军事理论', R.Junshi),
    new Subject('心理健康教育', R.Jiankang),
  ];
  List<List<Subject>> list = [];

  @override
  void initState() {
    list.add(_categoryList1);
    list.add(_categoryList2);
    list.add(_categoryList3);
    list.add(_categoryList4);
    list.add(_categoryList5);
    list.add(_categoryList6);
    list.add(_categoryList7);
    list.add(_categoryList8);
    //_girdViewList=list[_selectIndex];
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    //debugPaintSizeEnabled=true;
    ScreenUtil.init(
      BoxConstraints(
          maxWidth: MediaQuery.of(context).size.width,
          maxHeight: MediaQuery.of(context).size.height),
      designSize: Size(1080, 2340),
    );
    //计算右侧GridView的宽高比
    var leftWidth = ScreenUtil().setWidth(310);
    //右侧宽度=总宽度-左侧宽度-GridView外侧原生左右的Padding值-GirdView中间的间距
    var rightItemWidth =
        (ScreenUtil().screenWidth - leftWidth - 6 * ScreenUtil().setWidth(28)) /
            3;
    //rightItemWidth =ScreenUtil().setWidth(rightItemWidth);
    var rightItemHeight = ScreenUtil().setHeight(108);
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(ScreenUtil().setHeight(158)),
        child: AppBar(
          backgroundColor: Colors.white,
          titleSpacing: 15,
          elevation: 0,
          leading: IconButton(
            icon: Icon(Icons.arrow_back,color: Colors.black),
            onPressed: (){
              Navigator.pop(context);
            },
          ),
          //隐藏返回箭头
          title: Row(
            children: [
              // Image.asset(
              //   'assets/img/icon.png',
              //   width: ScreenUtil().setHeight(35),
              //   height: ScreenUtil().setHeight(35),
              //   fit: BoxFit.cover,
              // ),
              // SizedBox(
              //   width: ScreenUtil().setWidth(20),
              // ),
              Container(
                width: ScreenUtil().setWidth(840),
                child: Container(
                  decoration: new BoxDecoration(
                    color: Color(0xffF1F2F2),
                    borderRadius: BorderRadius.all(
                      Radius.circular(ScreenUtil().setHeight(18)),
                    ),
                  ),
                  alignment: Alignment.center,
                  height: ScreenUtil().setHeight(110),
                  child: JhLoginTextField(
                    border: InputBorder.none,
                    leftWidget: InkWell(
                      child: Container(
                          padding: EdgeInsets.all(8),
                          child: Icon(Icons.search, color: AppColors.subtext)),
                      onTap: () {},
                    ),
                    hintText: '输入课程名称',
                    isShowDeleteBtn: true,
                    isDense: false,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
      body: Container(
        color: Color(0xffF5F5F5),
        child: Row(
          children: [
            Container(
              width: ScreenUtil().setWidth(310),
              height: double.infinity,
              child: ListView.builder(
                itemCount: _categoryList.length,
                itemBuilder: (context, index) {
                  return InkWell(
                    onTap: () {
                      setState(
                        () {
                          _selectIndex = index;
                          _girdViewList.clear();
                          _girdViewList.addAll(list[index]);
                        },
                      );
                    },
                    child:
                    Builder(
                      builder: (_) {
                        if (_selectIndex + 1 == index ||
                            (index == 0 && _selectIndex != 0)) {
                          return Container(
                            color: Colors.white,
                            child: Container(
                              width: ScreenUtil().setWidth(310),
                              height: ScreenUtil().setHeight(174),
                              alignment: Alignment.center,
                              decoration: BoxDecoration(
                                color: _selectIndex == index
                                    ? Colors.white
                                    : Color(0xffF5F5F5),
                                borderRadius: BorderRadius.only(
                                    topRight: Radius.circular(8)),
                              ),
                              child: Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Container(
                                    width: ScreenUtil().setWidth(15),
                                    height: ScreenUtil().setHeight(70),
                                    decoration: BoxDecoration(
                                      color: _selectIndex == index
                                          ? AppColors.primary
                                          : Colors.white,
                                      borderRadius: BorderRadius.only(
                                        topRight: Radius.circular(
                                            ScreenUtil().setWidth(7)),
                                        bottomRight: Radius.circular(
                                            ScreenUtil().setWidth(7)),
                                      ),
                                    ),
                                  ),
                                  SizedBox(
                                    width: ScreenUtil().setWidth(10),
                                  ),
                                  Text(
                                    _categoryList[index],
                                    style: TextStyle(
                                      fontSize: ScreenUtil().setSp(53),
                                      color: _selectIndex == index
                                          ? AppColors.primary
                                          : Colors.black26,
                                      fontWeight: FontWeight.bold,
                                      fontFamily: '方正御墨行书',
                                    ),
                                  ),
                                ],
                              ),
                              padding: EdgeInsets.only(
                                  top: ScreenUtil().setHeight(33),
                                  bottom: ScreenUtil().setHeight(33)),
                            ),
                          );
                        } else if (_selectIndex - 1 == index) {
                          return Container(
                            color: Colors.white,
                            child: Container(
                              width: ScreenUtil().setWidth(310),
                              height: ScreenUtil().setHeight(174),
                              alignment: Alignment.center,
                              decoration: BoxDecoration(
                                color: _selectIndex == index
                                    ? Colors.white
                                    : Color(0xffF5F5F5),
                                borderRadius: BorderRadius.only(
                                    bottomRight: Radius.circular(8)),
                              ),
                              child: Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Container(
                                    width: ScreenUtil().setWidth(15),
                                    height: ScreenUtil().setHeight(70),
                                    decoration: BoxDecoration(
                                      color: _selectIndex == index
                                          ? AppColors.primary
                                          : Colors.white,
                                      borderRadius: BorderRadius.only(
                                        topRight: Radius.circular(
                                            ScreenUtil().setWidth(7)),
                                        bottomRight: Radius.circular(
                                            ScreenUtil().setWidth(7)),
                                      ),
                                    ),
                                  ),
                                  SizedBox(
                                    width: ScreenUtil().setWidth(10),
                                  ),
                                  Text(
                                    _categoryList[index],
                                    style: TextStyle(
                                      fontSize: ScreenUtil().setSp(53),
                                      color: _selectIndex == index
                                          ? AppColors.primary
                                          : Colors.black26,
                                      fontWeight: FontWeight.bold,
                                      fontFamily: '方正御墨行书',
                                    ),
                                  ),
                                ],
                              ),
                              padding: EdgeInsets.only(
                                  top: ScreenUtil().setHeight(33),
                                  bottom: ScreenUtil().setHeight(33)),
                            ),
                          );
                        } else {
                          return Container(
                            width: ScreenUtil().setWidth(310),
                            height: ScreenUtil().setHeight(174),
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              color: _selectIndex == index
                                  ? Colors.white
                                  : Color(0xffF5F5F5),
                            ),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Container(
                                  width: ScreenUtil().setWidth(15),
                                  height: ScreenUtil().setHeight(70),
                                  decoration: BoxDecoration(
                                    color: _selectIndex == index
                                        ? AppColors.primary
                                        : Colors.white,
                                    borderRadius: BorderRadius.only(
                                      topRight: Radius.circular(
                                          ScreenUtil().setWidth(7)),
                                      bottomRight: Radius.circular(
                                          ScreenUtil().setWidth(7)),
                                    ),
                                  ),
                                ),
                                SizedBox(
                                  width: ScreenUtil().setWidth(10),
                                ),
                                Text(
                                  _categoryList[index],
                                  style: TextStyle(
                                    fontSize: ScreenUtil().setSp(53),
                                    color: _selectIndex == index
                                        ? AppColors.primary
                                        : Colors.black26,
                                    fontWeight: FontWeight.bold,
                                    fontFamily: '方正御墨行书',
                                  ),
                                ),
                              ],
                            ),
                            padding: EdgeInsets.only(
                                top: ScreenUtil().setHeight(33),
                                bottom: ScreenUtil().setHeight(33)),
                          );
                        }
                      },
                    ),
                  );
                },
              ),
            ),
            Expanded(
              flex: 1,
              child: GirdViewItem(
                  key: ValueKey(_selectIndex), girdViewList: _girdViewList),
            ),
          ],
        ),
      ),
    );
  }
}



